package com.example.demo.controller;

import com.example.demo.common.ResultData;
import com.example.demo.entity.Student;
import com.example.demo.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.Optional;

@RestController
@CrossOrigin
public class HelloController {

    @Resource
    private UserService userService;

//    @GetMapping("/api/get_user_by_id/{id}")
//    public Student get_user(@PathVariable int id) {
//        Optional<Student> optById = userService.getOptById(id);
//        return optById.get();
//    }

    @GetMapping("/api/get_user_by_id/{id}")
    public ResultData get_user(@PathVariable int id) {
        Optional<Student> optById = userService.getOptById(id);
        if (!optById.isEmpty())
            return ResultData.success(optById.get());
        else
            return  ResultData.error(203,"id错误");
    }
}
